﻿using System;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Common
{
    public static class ResourceLoader
    {
        public static T Load<T>(string path) where T : Object
        {
            return Resources.Load<T>(path);
        }
        
        public static ResourceRequest LoadAsync<T>(string path, Action<ResourceRequest> action) where T : Object
        {
            ResourceRequest request = Resources.LoadAsync<T>(path);
            request.completed += operation =>
            {
                if (operation.isDone)
                {
                    action?.Invoke(request);
                }
            };
            return request;
        }
    }
}